<template>
  <div class="main">
    <div v-if="applies.length == 0" style="padding: 20px">案件无开票记录</div>
    <el-tabs @tab-click="applyClick" style="height: calc(100% - 10px)">
      <el-tab-pane v-for="apply in applies" :key="apply.CBA_ID" :label="apply.CBA_Name" style="height: calc(100%)">
        <div style="height: calc(100% - 50px); overflow: auto">
          <div style="overflow: auto">
            <el-divider>
              收费项目【{{ apply.ChargeSum }}元】
              <a v-if="apply.CBA_FormID" @click="toForm(apply.CBA_FormID)">
                <i class="el-icon-search"></i>跳转至审批流程
              </a>
              <a v-else @click="toOldForm(apply.CBA_ID)">
                <i class="el-icon-search"></i>跳转至审批流程
              </a>
            </el-divider>
            <el-table style="overflow: auto" :data="apply.Charges" stripe border highlight-current-row>
              <el-table-column type="index" width="60"></el-table-column>
              <el-table-column label="费用类型">
                <template slot-scope="scope">
                  {{ scope.row.CHTY_EnumTxt }}
                </template>
              </el-table-column>
              <el-table-column label="金额(元)" prop="CSCG_Fee">
                <template slot-scope="scope">
                  {{ scope.row.CSCG_Fee }}
                </template>
              </el-table-column>
              <el-table-column label="备注">
                <template slot-scope="scope">
                  {{ scope.row.CSCG_Remark }}
                </template>
              </el-table-column>
              <el-table-column fixed="right" label="操作">
                <template slot="header">
                  <el-button size="medium" type="text" slot="reference" icon="el-icon-plus" @click="
                    curCharge = {}
                  addChargeVis = true
                    "></el-button>
                </template>
                <template slot-scope="scope">
                  <el-button type="text" size="small" icon="el-icon-edit" @click="
                    curCharge = scope.row
                  editChargeVis = true
                    ">
                    修改
                  </el-button>
                  <el-button type="text" size="small" icon="el-icon-delete" @click="deleteCharge(scope.row.CSCG_ID)">
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div style="background-color: aliceblue; margin-top: 40px">
            <el-divider>票据详情【{{ apply.BillSum }}元】</el-divider>
            <div>
              <el-button type="text" style="margin-left: 10px" icon="el-icon-plus" @click="
                curBill = {}
              addBillVis = true
                ">
                票据录入
              </el-button>
              <el-button type="text" style="margin-left: 10px" icon="el-icon-plus">
                保单开票(未实现)
              </el-button>
            </div>
            <div :gutter="10" style="overflow: auto; display: flex; flex-wrap: wrap">
              <div style="
                  background-color: white;
                  border: 1px solid #cbcbcb;
                  width: 350px;
                  height: 190px;
                  display: block;
                  padding: 10px;
                  margin: 0 28px 10px 0;
                " v-for="(item, index) in apply.Bills" :key="index">
                <bill-card :bill="item" @deleteReturn="getApplyInfos()"></bill-card>
                <div style="
                    width: 100%;
                    border-top: 1px solid #e3e3e3;
                    margin-top: 8px;
                  ">
                  <!-- <el-button
                    type="text"
                    size="mini"
                    v-if="item.CSB_Status == 100"
                    @click="
                      () => {
                        curBill = item
                        curReturn = {}
                        addReturnVis = true
                      }
                    "
                  >
                    回款
                  </el-button> -->
                  <el-button type="text" size="mini" @click="
                    () => {
                      curBill = item
                      editBillVis = true
                    }
                  ">
                    修改
                  </el-button>
                  <el-button type="text" size="mini" @click="deleteBill(item.CSB_ID)">
                    删除
                  </el-button>
                  <el-button type="text" size="mini" v-if="item.CSB_Status == 100" @click="
                    () => {
                      curBill = item
                      refundBillVis = true
                    }
                  ">
                    退票
                  </el-button>
                  <el-button type="text" size="mini" v-if="item.CSB_Status == -100" @click="
                    () => {
                      curBill = item
                      curBill.CSB_RefundID = item.CSB_ID
                      curBill.CSB_RefundReason = curBill.CSB_RefundTime = null
                      rebillVis = true
                    }
                  ">
                    重开
                  </el-button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>

    <el-drawer title="票据录入" :visible.sync="addBillVis" :with-header="false" direction="rtl" size="540px">
      <el-form v-if="curBill" label-width="100px" label-position="left" style="
          margin-left: 20px;
          margin-top: 20px;
          overflow: auto;
          height: 100vh;
        ">
        <el-form-item label="扫描件">
          <el-upload ref="upload" class="avatar-uploader" :action="fileUploadUrl" :show-file-list="false"
            :on-progress="onProgress" :on-error="uploadErr" :on-success="uploadSuccess" :headers="myHeaders">
            <el-image class="avatar" fit="fill" v-if="curBill.FL_SrcPath"
              :src="fileURL + curBill.FL_SrcPath"></el-image>
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <el-progress v-if="uploadPercentage" :percentage="uploadPercentage"></el-progress>
        </el-form-item>
        <el-form-item v-if="ticketFile">
          <ticketIdentify :file="ticketFile" @output="ticketAIOutput" />
        </el-form-item>
        <el-form-item>
          <el-checkbox label="发票销售方默认为案件处理机构" v-model="defaultSaleCompany"></el-checkbox>
        </el-form-item>
        <el-form-item label="销售方" v-if="!defaultSaleCompany">
          <el-select style="width: 360px" v-model="curBill.CSB_SaleCompanyID" filterable remote reserve-keyword
            placeholder="请输入（全称/简称/税号..）关键词搜索" :remote-method="getCompanies" :loading="loading">
            <el-option v-for="item in companies" :key="item.CMP_ID" :label="item.CMP_Name"
              :value="item.CMP_ID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="购买方">
          <el-select style="width: 360px" v-model="curBill.CSB_BuyCompanyID" filterable remote reserve-keyword
            placeholder="请输入（全称/简称/税号..）关键词搜索" :remote-method="getCompanies" :loading="loading">
            <el-option v-for="item in companies" :key="item.CMP_ID" :label="item.CMP_Name"
              :value="item.CMP_ID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="转账人">
          <el-select style="width: 360px" v-model="curBill.CSB_BuyEmployeeID" filterable remote reserve-keyword
            placeholder="请输入转账人关键词（姓名/手机号）搜索" :remote-method="getEmployees" :loading="loading">
            <el-option v-for="item in employees" :key="item.ECV_TargetID" :label="item.CMP_Name
              ? item.CMP_Name + '_' + item.USR_Name
              : item.USR_Name
              " :value="item.ECV_TargetID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="编号">
          <el-input v-model="curBill.CSB_No" style="width: 360px"></el-input>
        </el-form-item>
        <el-form-item label="票税合计(元)">
          <el-input-number v-model="curBill.CSB_Fee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="金额(元)">
          <el-input-number v-model="curBill.CSB_WithOutTaxFee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="税额(元)">
          <el-input-number v-model="curBill.CSB_TaxFee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="开票日期">
          <el-date-picker align="right" v-model="curBill.CSB_BillDate" placeholder="请选择开票日期"
            value-format="yyyy-MM-dd HH:mm:ss" type="date" style="width: 360px"></el-date-picker>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="curBill.CSB_Remark" style="width: 360px" type="textarea" :rows="3"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="addBill()">录入</el-button>
          <el-button type="text" @click="addBillVis = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-drawer>

    <el-drawer title="票据修改" :visible.sync="editBillVis" :with-header="false" direction="rtl" size="540px">
      <el-form v-if="curBill" label-width="100px" label-position="left" style="
          margin-left: 20px;
          margin-top: 20px;
          overflow: auto;
          height: 100vh;
        ">
        <el-form-item label="扫描件">
          <el-upload ref="upload" class="avatar-uploader" :action="fileUploadUrl" :show-file-list="false"
            :on-progress="onProgress" :on-error="uploadErr" :on-success="uploadSuccess" :headers="myHeaders">
            <el-image class="avatar" fit="fill" v-if="curBill.FL_SrcPath"
              :src="fileURL + curBill.FL_SrcPath"></el-image>
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <el-progress v-if="uploadPercentage" :percentage="uploadPercentage"></el-progress>
        </el-form-item>
        <el-form-item>
          <el-checkbox label="发票销售方默认为案件处理机构" v-model="defaultSaleCompany"></el-checkbox>
        </el-form-item>
        <el-form-item label="销售方" v-if="!defaultSaleCompany">
          <el-input v-model="curBill.SaleCompanyName" style="width: 360px" v-if="!curBill.EditSaleCompany" readonly>
            <template slot="append">
              <el-button icon="el-icon-edit" @click="
                $set(curBill, 'EditSaleCompany', true)
              curBill.CSB_SaleCompanyID = null
                "></el-button>
            </template>
          </el-input>
          <el-select v-if="curBill.EditSaleCompany" style="width: 360px" v-model="curBill.CSB_SaleCompanyID" filterable
            remote reserve-keyword placeholder="请输入（全称/简称/税号..）关键词搜索" :remote-method="getCompanies" :loading="loading">
            <el-option v-for="item in companies" :key="item.CMP_ID" :label="item.CMP_Name"
              :value="item.CMP_ID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="购买方">
          <el-input v-model="curBill.BuyCompanyName" style="width: 360px" v-if="!curBill.EditBuyCompany" readonly>
            <template slot="append">
              <el-button icon="el-icon-edit" @click="
                $set(curBill, 'EditBuyCompany', true)
              curBill.CSB_BuyCompanyID = null
                "></el-button>
            </template>
          </el-input>
          <el-select style="width: 360px" v-model="curBill.CSB_BuyCompanyID" filterable remote reserve-keyword
            placeholder="请输入（全称/简称/税号..）关键词搜索" :remote-method="getCompanies" :loading="loading"
            v-if="curBill.EditBuyCompany">
            <el-option v-for="item in companies" :key="item.CMP_ID" :label="item.CMP_Name"
              :value="item.CMP_ID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="转账人">
          <el-input v-model="curBill.BuyEmployeeName" style="width: 360px" v-if="!curBill.EditBuyEmployee" readonly>
            <template slot="append">
              <el-button icon="el-icon-edit" @click="
                $set(curBill, 'EditBuyEmployee', true)
              curBill.CSB_BuyEmployeeID = null
                "></el-button>
            </template>
          </el-input>
          <el-select v-if="curBill.EditBuyEmployee" style="width: 360px" v-model="curBill.CSB_BuyEmployeeID" filterable
            remote reserve-keyword placeholder="请输入转账人关键词（姓名/手机号）搜索" :remote-method="getEmployees" :loading="loading">
            <el-option v-for="item in employees" :key="item.ECV_TargetID" :label="item.CMP_Name
              ? item.CMP_Name + '_' + item.USR_Name
              : item.USR_Name
              " :value="item.ECV_TargetID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="编号">
          <el-input v-model="curBill.CSB_No" style="width: 360px"></el-input>
        </el-form-item>
        <el-form-item label="票税合计(元)">
          <el-input-number v-model="curBill.CSB_Fee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="金额(元)">
          <el-input-number v-model="curBill.CSB_WithOutTaxFee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="税额(元)">
          <el-input-number v-model="curBill.CSB_TaxFee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="开票日期">
          <el-date-picker align="right" v-model="curBill.CSB_BillDate" placeholder="请选择开票日期"
            value-format="yyyy-MM-dd HH:mm:ss" type="date" style="width: 360px"></el-date-picker>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="curBill.CSB_Remark" style="width: 360px" type="textarea" :rows="3"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="warning" @click="editBill()">保存</el-button>
          <el-button type="text" @click="editBillVis = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-drawer>

    <el-drawer title="票据重开" :visible.sync="rebillVis" :with-header="false" direction="rtl" size="540px">
      <el-form v-if="curBill" label-width="100px" label-position="left" style="
          margin-left: 20px;
          margin-top: 20px;
          overflow: auto;
          height: 100vh;
        ">
        <el-form-item label="扫描件">
          <el-upload ref="upload" class="avatar-uploader" :action="fileUploadUrl" :show-file-list="false"
            :on-progress="onProgress" :on-error="uploadErr" :on-success="uploadSuccess" :headers="myHeaders">
            <el-image class="avatar" fit="fill" v-if="curBill.FL_SrcPath"
              :src="fileURL + curBill.FL_SrcPath"></el-image>
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <el-progress v-if="uploadPercentage" :percentage="uploadPercentage"></el-progress>
        </el-form-item>
        <el-form-item v-if="ticketFile">
          <ticketIdentify :file="ticketFile" @output="ticketAIOutput" />
        </el-form-item>
        <el-form-item>
          <el-checkbox label="发票销售方默认为案件处理机构" v-model="defaultSaleCompany"></el-checkbox>
        </el-form-item>
        <el-form-item label="销售方" v-if="!defaultSaleCompany">
          <el-input v-model="curBill.SaleCompanyName" style="width: 360px" v-if="!curBill.EditSaleCompany" readonly>
            <template slot="append">
              <el-button icon="el-icon-edit" @click="
                $set(curBill, 'EditSaleCompany', true)
              curBill.CSB_SaleCompanyID = null
                "></el-button>
            </template>
          </el-input>
          <el-select v-if="curBill.EditSaleCompany" style="width: 360px" v-model="curBill.CSB_SaleCompanyID" filterable
            remote reserve-keyword placeholder="请输入（全称/简称/税号..）关键词搜索" :remote-method="getCompanies" :loading="loading">
            <el-option v-for="item in companies" :key="item.CMP_ID" :label="item.CMP_Name"
              :value="item.CMP_ID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="购买方">
          <el-input v-model="curBill.BuyCompanyName" style="width: 360px" v-if="!curBill.EditBuyCompany" readonly>
            <template slot="append">
              <el-button icon="el-icon-edit" @click="
                $set(curBill, 'EditBuyCompany', true)
              curBill.CSB_BuyCompanyID = null
                "></el-button>
            </template>
          </el-input>
          <el-select style="width: 360px" v-model="curBill.CSB_BuyCompanyID" filterable remote reserve-keyword
            placeholder="请输入（全称/简称/税号..）关键词搜索" :remote-method="getCompanies" :loading="loading"
            v-if="curBill.EditBuyCompany">
            <el-option v-for="item in companies" :key="item.CMP_ID" :label="item.CMP_Name"
              :value="item.CMP_ID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="转账人">
          <el-input v-model="curBill.BuyEmployeeName" style="width: 360px" v-if="!curBill.EditBuyEmployee" readonly>
            <template slot="append">
              <el-button icon="el-icon-edit" @click="
                $set(curBill, 'EditBuyEmployee', true)
              curBill.CSB_BuyEmployeeID = null
                "></el-button>
            </template>
          </el-input>
          <el-select v-if="curBill.EditBuyEmployee" style="width: 360px" v-model="curBill.CSB_BuyEmployeeID" filterable
            remote reserve-keyword placeholder="请输入转账人关键词（姓名/手机号）搜索" :remote-method="getEmployees" :loading="loading">
            <el-option v-for="item in employees" :key="item.ECV_TargetID" :label="item.CMP_Name
              ? item.CMP_Name + '_' + item.USR_Name
              : item.USR_Name
              " :value="item.ECV_TargetID"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="编号">
          <el-input v-model="curBill.CSB_No" style="width: 360px"></el-input>
        </el-form-item>
        <el-form-item label="票税合计(元)">
          <el-input-number v-model="curBill.CSB_Fee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="金额(元)">
          <el-input-number v-model="curBill.CSB_WithOutTaxFee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="税额(元)">
          <el-input-number v-model="curBill.CSB_TaxFee" :precision="2" style="width: 360px"></el-input-number>
        </el-form-item>
        <el-form-item label="开票日期">
          <el-date-picker align="right" v-model="curBill.CSB_BillDate" placeholder="请选择开票日期"
            value-format="yyyy-MM-dd HH:mm:ss" type="date" style="width: 360px"></el-date-picker>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="curBill.CSB_Remark" style="width: 360px" type="textarea" :rows="3"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="warning" @click="reBill()">重开</el-button>
          <el-button type="text" @click="rebillVis = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-drawer>

    <el-dialog title="退票" :visible.sync="refundBillVis" width="500px" :modal-append-to-body="false" center>
      <el-form v-if="curBill" label-width="80px" label-position="left">
        <el-form-item label="退票日期">
          <el-date-picker align="right" v-model="curBill.CSB_RefundTime" placeholder="请选择退票日期"
            value-format="yyyy-MM-dd HH:mm:ss" type="date" style="width: 360px"></el-date-picker>
        </el-form-item>
        <el-form-item label="原因">
          <el-input v-model="curBill.CSB_RefundReason" style="width: 360px" type="textarea" :rows="2"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" @click="refundBill()">退票</el-button>
          <el-button type="text" @click="refundBillVis = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="添加费用项目" :visible.sync="addChargeVis" width="500px" :modal-append-to-body="false" center>
      <el-form label-width="auto" label-position="right" v-if="curCharge">
        <el-form-item label="类型">
          <div style="display: flex">
            <el-select style="flex: 1" v-model="curCharge.CSCG_TypeID" placeholder="请选择费用类型">
              <el-option v-for="item in chargeTypes" :key="item.CHTY_ID" :label="item.CHTY_EnumTxt"
                :value="item.CHTY_EnumValue"></el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="金额(元)">
          <div style="display: flex">
            <el-input-number style="flex: 1" v-model="curCharge.CSCG_Fee" :precision="2"></el-input-number>
          </div>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="curCharge.CSCG_Remark" placeholder="请输入备注" @input="input"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addCharge">新增</el-button>
          <el-button type="text" @click="addChargeVis = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="费用项目修改" :visible.sync="editChargeVis" width="500px" :modal-append-to-body="false" center>
      <el-form label-width="auto" label-position="right" v-if="curCharge">
        <el-form-item label="类型">
          <div style="display: flex">
            <el-select style="flex: 1" v-model="curCharge.CSCG_TypeID" placeholder="请选择费用类型">
              <el-option v-for="item in chargeTypes" :key="item.CHTY_ID" :label="item.CHTY_EnumTxt"
                :value="item.CHTY_EnumValue"></el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="金额(元)">
          <div style="display: flex">
            <el-input-number style="flex: 1" v-model="curCharge.CSCG_Fee" :precision="2"></el-input-number>
          </div>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="curCharge.CSCG_Remark" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="warning" @click="editCharge">保存</el-button>
          <el-button type="text" @click="editChargeVis = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- <el-dialog
      title="添加回款"
      :visible.sync="addReturnVis"
      width="500px"
      :modal-append-to-body="false"
      center
    >
      <el-form label-width="auto" label-position="right" v-if="curReturn">
        <el-form-item label="机构回款日期">
          <el-date-picker
            align="right"
            v-model="curReturn.CSBR_CompanyAccountTime"
            placeholder="请选择机构回款日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="date"
            style="width: 360px"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="平台回款日期">
          <el-date-picker
            align="right"
            v-model="curReturn.CSBR_AccountTime"
            placeholder="请选择平台回款日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="date"
            style="width: 360px"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="金额(元)">
          <div style="display: flex">
            <el-input-number
              style="flex: 1"
              v-model="curReturn.CSBR_Fee"
              :precision="2"
            ></el-input-number>
          </div>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="curReturn.CSBR_Remark"
            placeholder="请输入备注"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addBillReturn">保存</el-button>
          <el-button type="text" @click="addReturnVis = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog> -->
  </div>
</template>
<script>
import ticketIdentify from './ticketIdentify.vue'
import {
  getChargeTypes,
  getApplyInfos,
  getCompanies,
  getEmployees,
  reBill,
  addBill,
  editBill,
  deleteBill,
  refundBill,
  addCharge,
  deleteCharge,
  editCharge,
  addBillReturn,
} from '@/api/core/caseBillApply'
import {
  baseURL,
  fileRoot,
  fileUploadRoot,
  empIdName,
  tokenName,
} from '@/config'
import billCard from './billCard.vue'
export default {
  components: { ticketIdentify, billCard },
  props: ['caseId'],
  data: function () {
    return {
      chargeTypes: [],
      applies: [],
      companies: [],
      employees: [],

      curApply: null,

      curCharge: null,
      addChargeVis: false,
      editChargeVis: false,

      defaultSaleCompany: true,
      curBill: null,
      addBillVis: false,
      editBillVis: false,
      refundBillVis: false,
      rebillVis: false,

      curReturn: null,
      addReturnVis: false,

      loading: false,

      fileURL: baseURL + fileRoot,
      fileUploadUrl: baseURL + fileUploadRoot,
      myHeaders: {},
      uploadPercentage: 0,
      ticketFile: null,
    }
  },
  methods: {
    toOldForm(formId) {
      window.open('http://111.230.247.78:8443/#/myWorkflow/handleCaseBill/' + formId, '_blank')
    },
    ticketAIOutput(val) {
      // this.curBill.CSB_BillDate = val.dealdate
      // this.curBill.CSB_No = val.invNo
      // this.curBill.CSB_Fee = val.fee
      // this.curBill.CSB_TaxFee = val.taxFee
      // this.curBill.CSB_WithOutTaxFee = val.feeWithoutTax
      this.$set(this.curBill, 'CSB_BillDate', val.dealdate)
      this.$set(this.curBill, 'CSB_No', val.invNo)
      this.$set(this.curBill, 'CSB_Fee', val.fee)
      this.$set(this.curBill, 'CSB_TaxFee', val.taxFee)
      this.$set(this.curBill, 'CSB_WithOutTaxFee', val.feeWithoutTax)
      this.loading = true
      getCompanies({
        keyword: val.purchaserName,
      }).then(({ data }) => {
        console.log(data.Items)
        this.companies = data.Items
        if (this.companies.length > 0) {
          this.curBill.BuyCompanyName = this.companies[0].CMP_Name
          this.curBill.CSB_BuyCompanyID = this.companies[0].CMP_ID
        }
        this.loading = false
      })
      this.$forceUpdate()
    },
    applyClick(tab) {
      this.curApply = this.applies[tab.index]
    },
    toForm(formId) {
      this.$router.push({
        name: 'formInfoPage',
        query: { formId },
      })
    },
    getChargeTypes() {
      getChargeTypes().then(({ data }) => {
        this.chargeTypes = data
      })
    },
    getCompanies(keyword) {
      if (keyword.length >= 2) {
        this.loading = true
        getCompanies({
          keyword,
        }).then(({ data }) => {
          this.companies = data.Items
          this.loading = false
        })
      }
    },
    getEmployees(keyword) {
      if (keyword.length >= 1) {
        this.loading = true
        getEmployees({
          keyword,
        }).then(({ data }) => {
          this.employees = data.Items
          this.loading = false
        })
      }
    },
    uploadSuccess(res) {
      if (res.success) {
        let file = res.data
        this.$set(this.curBill, 'FL_Name', file.FL_Name)
        this.$set(this.curBill, 'FL_SrcPath', file.FL_SrcPath)
        this.$set(this.curBill, 'CSB_FileID', file.FL_ID)
        this.uploadPercentage = 0
        this.ticketFile = this.$refs.upload.uploadFiles.pop().raw
      } else {
        alert(res.errormsg)
      }
    },
    uploadErr(err) {
      alert(JSON.stringify(err))
    },
    onProgress(event) {
      this.uploadPercentage = Math.round(event.percent * 100) / 100
    },
    getApplyInfos() {
      getApplyInfos(this.caseId).then(({ data }) => {
        this.applies = data
        this.curApply = this.applies.length > 0 ? this.applies[0] : null
      })
    },
    addCharge() {
      this.curCharge.CSCG_ApplyID = this.curApply.CBA_ID
      addCharge(this.curCharge).then(() => {
        this.getApplyInfos()
        this.addChargeVis = false
      })
    },
    editCharge() {
      this.$confirm(`是否保存修改？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        editCharge(this.curCharge).then(() => {
          this.getApplyInfos()
          this.editChargeVis = false
        })
      })
    },
    deleteCharge(id) {
      this.$confirm(`是否删除该收费项目？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteCharge(id).then(() => {
          this.getApplyInfos()
        })
      })
    },
    addBill() {
      this.curBill.CSB_ApplyID = this.curApply.CBA_ID
      addBill(this.curBill).then(() => {
        this.getApplyInfos()
        this.addBillVis = false
      })
    },
    reBill() {
      reBill(this.curBill).then(() => {
        this.getApplyInfos()
        this.rebillVis = false
      })
    },
    editBill() {
      this.$confirm(`是否保存修改？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        editBill(this.curBill).then(() => {
          this.getApplyInfos()
          this.editBillVis = false
        })
      })
    },
    deleteBill(id) {
      this.$confirm(`是否删除该票据？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteBill(id).then(() => {
          this.getApplyInfos()
        })
      })
    },
    refundBill() {
      if (!this.curBill) {
        return
      }
      this.$confirm(`是否退票？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        refundBill(this.curBill).then(() => {
          this.getApplyInfos()
          this.refundBillVis = false
        })
      })
    },
    // addBillReturn() {
    //   this.curReturn.CSBR_BillID = this.curBill.CSB_ID
    //   addBillReturn(this.curReturn).then(() => {
    //     this.getApplyInfos()
    //     this.addReturnVis = false
    //   })
    // },
  },
  created: function () {
    if (!this.caseId) {
      return
    }
    this.myHeaders[tokenName] = this.$store.getters['user/accessToken']
    this.myHeaders[empIdName] = this.$store.getters['user/curEmp'].EMP_ID
    this.getApplyInfos()
    this.getChargeTypes()
  },
}
</script>
<style>
.el-drawer.rtl {
  overflow: scroll;
}
</style>
<style scoped>
.main {
  height: 100%;
  overflow: auto;
}

.header {
  width: 100%;
  padding-top: 10px;
  padding-bottom: 10px;
  height: auto;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  background: #ffffff;
  border-radius: 5px;
  border-bottom: #f4f8ff 2px solid;
  display: flex;
  margin-bottom: 11px;
  align-items: center;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 300px;
  height: 220px;
  line-height: 220px;
  text-align: center;
  border-style: dashed;
  border-width: thin;
}

.avatar {
  width: 300px;
  height: 220px;
  display: block;
  border-style: dashed;
  border-width: thin;
}
</style>
